package com.ijiuchuang.jc_localization.tools.views;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ijiuchuang.jc_localization.tools.utils.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 王伟 on 2016/6/28
 * Function : 评论回复控件
 */
public class CommentsLayout extends LinearLayout {

    private Context context;
    private List<Comment> commentList = new ArrayList<>();

    public CommentsLayout(Context context) {
        this(context, null);
    }

    public CommentsLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CommentsLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        this.context = context;
        init();
    }

    private void init() {
        setOrientation(VERTICAL);
    }

    public void showComments(Comment ... comments) {
    }

    public void showComments(List<Comment> list) {
        if (list.isEmpty()) {
            return;
        } else {
            for (Comment comment : list) {
                TextView textView = new TextView(context);
                LinearLayout.LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                textView.setLayoutParams(params);
                CommentTextView.with(textView)
                        .user(comment.getUserA())
                        .reply(comment.getUserB())
                        .say(comment.getComment())
                        .show(new CommentTextView.CommentClickListener() {
                            @Override
                            public void onUserAClick(String userA) {
                                Log.i("userA: " + userA);
                            }

                            @Override
                            public void onUserBClick(String userB) {
                                Log.i("userB: " + userB);
                            }

                            @Override
                            public void onCommentClick(String comment) {
                                Log.i("comment: " + comment);
                            }
                        });
                addView(textView);
            }
        }
    }

    public static class Comment {
        private String userA;
        private String userB;
        private String comment;

        public Comment(String userA, String userB, String comment) {
            this.userA = userA;
            this.userB = userB;
            this.comment = comment;
        }

        @Override
        public String toString() {
            return "Comment{" +
                    "userA='" + userA + '\'' +
                    "userB='" + userB + '\'' +
                    "comment='" + comment + '\'' +
                    '}';
        }

        public String getUserA() {
            return userA;
        }

        public String getUserB() {
            return userB;
        }

        public String getComment() {
            return comment;
        }
    }
}
